/**
 * User: alesj
 * Date: 2005.6.1
 * Time: 15:33:28
 * 
 * (C) Genera Lynx d.o.o.
 */

package com.alesj.newsfeed.data;

import com.generalynx.common.resources.Resources;
import com.generalynx.ecos.data.Person;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class ReporterContact extends Contact implements Serializable {

    private static final long serialVersionUID = 1L;

    private Person person;
    private String media;
    private String company;
    private String email2;
    private String title;

    public void beforeBind() {
        super.beforeBind();
        setPerson(new Person());
    }

    public String getAddLabel() {
        return Resources.getString(Resources.PERSON);
    }

    private String identityString(boolean surnameFirst) {
        if (getPerson() != null && StringUtils.hasText(getPerson().toString())) {
            return getPerson().toString(surnameFirst);
        } else if (StringUtils.hasText(getCompany())) {
            return getCompany();
        } else if (StringUtils.hasText(getMedia())) {
            return getMedia();
        } else if (StringUtils.hasText(getEmail())) {
            return getEmail();
        } else {
            return "[no identity]";
        }
    }

    public String getLabel() {
        return identityString(true);
    }

    protected String getNameLabel() {
        return identityString(false) + nonActiveLabel();
    }

    public List getTokens() {
        List tokens = new ArrayList();
        tokens.add(person != null ? person.getName() : "");
        tokens.add(person != null ? person.getSurname() : "");
        tokens.addAll(Arrays.asList(media, company, email2, title));
        tokens.addAll(super.getTokens());
        return tokens;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public String toString() {
        return identityString(false) + " [" + getEmail() + "]";
    }

    public String getMedia() {
        return media;
    }

    public void setMedia(String media) {
        this.media = media;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getEmail2() {
        return email2;
    }

    public void setEmail2(String email2) {
        this.email2 = email2;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

}
